package backend.server;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;
import backend.core.transport.Decoder;
import backend.core.transport.Encoder;
import backend.core.transport.Package;

/**
 * 
 */
public class LiveEncoder extends MessageToByteEncoder<Package> {
    @Override
    public void encode(ChannelHandlerContext ctx, Package msg, ByteBuf out)
            throws Exception {
        Encoder encoder = Encoder.getInstance();
        Decoder decoder = Decoder.getInstance();
        //
        byte[] data = encoder.encode(msg);
        String raw = decoder.hexEncode(data);

        out.writeBytes(Unpooled.copiedBuffer(raw.getBytes()));

    }
}